package com.huibei.wateradmin.authority.controller;

import com.huibei.wateradmin.authority.domain.Menu;
import com.huibei.wateradmin.authority.message.ClientMenuInfo;
import com.huibei.wateradmin.authority.message.ReqDateTablesMsg;
import com.huibei.wateradmin.authority.message.ReqUpdateMenuMsg;
import com.huibei.wateradmin.authority.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by wanglinlin on 2016/7/20.
 */
@RestController
@RequestMapping(value = "/admin/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/listPage",method = RequestMethod.GET)
    public ModelAndView listPage() {
        ModelAndView mv = new ModelAndView("menu/list");
        return mv;
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Page<Menu> list(ReqDateTablesMsg msg) {
        return menuService.findAll(new PageRequest(msg.getPageNum(), msg.getLength()));
    }

    @RequestMapping(value = "/get/{id}")
    public ClientMenuInfo findById(@PathVariable Long id) {
       return menuService.findById(id);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public void update(ReqUpdateMenuMsg msg) {
        menuService.updateMenu(msg.getMenuId(),msg.getName(),msg.getUrl(),msg.getIcon(),msg.getParentId());
    }

}
